package servlet;

import entity.Rs;
import service.RsService;
import service.impl.RsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/UpdateServlet")
public class UpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        Rs rs = new Rs();
        String id = request.getParameter("id");
        rs.setPost_code(request.getParameter("code"));
        rs.setPost_name(request.getParameter("name"));
        rs.setPost_sort(request.getParameter("sort"));
        rs.setStatus(request.getParameter("status"));
        rs.setTime(request.getParameter("time"));
        RsServiceImpl  service = new RsService();
        int update = service.update(rs,id);
        request.setAttribute("update",update);
        request.getRequestDispatcher("LoginServlet").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
